package com.tgu.home_action.pojo;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.util.Map;

@Data
public class Family {
    public interface update {
    }

    @NotNull(message = "id不能为空", groups = {update.class})
    @ApiModelProperty("家属ID")
    private Integer id;

    @ApiModelProperty("姓名")
    private String name;

    @ApiModelProperty("手机号")
    private String phone;

    @ApiModelProperty("性别")
    private Short sex;

    @ApiModelProperty("昵称")
    private String nickName;

    @ApiModelProperty("头像")
    private String avatarUrl;

    @ApiModelProperty("国家")
    private String country;

    @ApiModelProperty("省份")
    private String province;

    @ApiModelProperty("城市")
    private String city;

    @ApiModelProperty("区")
    private String district;

    @JsonIgnore
    private String openid;
    /**
     * 账号状态，0为被封禁，1为正常，2为正在申请解封
     */
    @ApiModelProperty("账号状态")
    private Short state;

    @ApiModelProperty(value = "注册时间", dataType = "java.sql.Date")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Timestamp registerTime;

    @ExcelIgnore
    @JsonBackReference("当前页")
    @ApiModelProperty("当前页")
    private Integer pageNo;

    @ExcelIgnore
    @JsonBackReference("每页条数")
    @ApiModelProperty("每页条数")
    private Integer pageSize;

    @JsonIgnore
    private Integer startSize;

    @JsonIgnore
    private String sessionKey;


    public Family() {
    }

    public Family(Integer id) {
        this.id = id;
    }


    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", phone='" + phone + '\'' +
                ", sex=" + sex +
                ", nickName='" + nickName + '\'' +
                ", avatarUrl='" + avatarUrl + '\'' +
                ", country='" + country + '\'' +
                ", city='" + city + '\'' +
                ", province='" + province + '\'' +
                ", openid='" + openid + '\'' +
                ", state=" + state +
                '}';
    }

    @JsonIgnore
    public static boolean userinfoIsNull(Family family) {
        return family.nickName == null && family.avatarUrl == null && family.sex == null;

    }

    @JsonIgnore
    public static Boolean compareUserinfo(Family family1, Family family2) {
        return family1.nickName.equals(family2.nickName) && family1.avatarUrl.equals(family2.avatarUrl);
    }

    /**
     * 设置微信获取的全部用户信息
     *
     * @param data：微信用户信息
     */
    @ApiModelProperty(hidden = true)
    public void setAllUserinfo(Map<String, Object> data) {
        int gender = (int) data.get("gender");
        sex = (short) gender;
        this.nickName = (String) data.get("nickName");
        this.avatarUrl = (String) data.get("avatarUrl");
    }

    /**
     * 设置微信获取的用户信息，只包括头像和昵称
     *
     * @param data：微信用户信息
     */
    @ApiModelProperty(hidden = true)
    public void setUserinfo(Map<String, Object> data) {
        this.nickName = (String) data.get("nickName");
        this.avatarUrl = (String) data.get("avatarUrl");
    }
}
